/*
	Simple Software Renderer (SSRenderer)
	Copyright (C) 2007 Piotr Orzechowski <piotr.orzechowski@gmail.com>

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "./devices/SDLDevice/SDLDevice.h"
#include "./utilities/Profiler.h"

#include <iostream>
#include <unistd.h>

namespace dev = deviceSDL;

using namespace dev;
using namespace ssr;

int main(int argc, char *argv[])
{
	ISSRDevice *pDevice;			// Interface of the display device
	SSRRenderer *pRenderer;	        // Renderer

	// Initialize window and get interface to the display device
	createDevice<SSRDevice>(pDevice, 640, 480, "window name");

	pRenderer = SSRRenderer::CreateRenderer();
	pRenderer->SetRenderTarget(pDevice->GetRenderTarget());
std::cout<<"sadasdas"<<std::endl;
std::cout.flush();
	//pRenderer->GetErrorStack().AddOutputStream(std::cout);

	const char* outBuffer;
	color32 c;

	for(;;)
	{

PROFILE_START_LOOP
	PROFILE_BEGIN("draw")

		pRenderer->BeginDrawing();
		pRenderer->ClearColorBuffer(0xFFFFFF);

		for(int i = 0; i < 20000; ++i)
		{
			c.r = rand() % 255;
			c.b = rand() % 255;
			pRenderer->BlendPixel_Alpha_0_125(rand() % 640, rand() % 480, c);
		}
		pRenderer->EndDrawing();

	PROFILE_END
	PROFILE_BEGIN("swap")

		pDevice->FlushBuffers();

	PROFILE_END
PROFILE_END_LOOP

PROFILE_GET_OUTPUT(outBuffer);

	std::cout << outBuffer;
    util::Profiler::GetInstance().ChildSample();
	}

	// Destroy the renderer
	SSR_RELEASE(pRenderer);

	// Lastly, destroy the display device
	SSR_RELEASE(pDevice);

	return 0;
}
